<html>
<head><meta charset="utf-8"><title>step_by =&gt; optimization fail #84621 · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/step_by.20.3D.3E.20optimization.20fail.20.2384621.html">step_by =&gt; optimization fail #84621</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236387398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/step_by%20%3D%3E%20optimization%20fail%20%2384621/near/236387398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/step_by.20.3D.3E.20optimization.20fail.20.2384621.html#236387398">(Apr 27 2021 at 18:35)</a>:</h4>
<p>Someone asked me about this (and provided godbolt links); I’ve transcribed it into an issue but wanted to also ask here</p>



<a name="236387555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/step_by%20%3D%3E%20optimization%20fail%20%2384621/near/236387555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/step_by.20.3D.3E.20optimization.20fail.20.2384621.html#236387555">(Apr 27 2021 at 18:36)</a>:</h4>
<p>I’m currently guessing that the use of <code>step_by</code> is causing some extra panic_bounds_checks to be emitted (or fail to be eliminated)</p>



<a name="236395681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/step_by%20%3D%3E%20optimization%20fail%20%2384621/near/236395681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/step_by.20.3D.3E.20optimization.20fail.20.2384621.html#236395681">(Apr 27 2021 at 19:35)</a>:</h4>
<p><code>step_by</code> is known to be a bit problematic, see <a href="https://github.com/rust-lang/rust/issues/51557">https://github.com/rust-lang/rust/issues/51557</a> for example.  There's also <a href="https://github.com/rust-lang/rust/issues/52065">https://github.com/rust-lang/rust/issues/52065</a> that left the semantics open a bit to allow the implementation to be tweaked to a different version that might be more efficient.  And nikic did some work that might have improved some of this, in <a href="https://github.com/rust-lang/rust/issues/52203">https://github.com/rust-lang/rust/issues/52203</a></p>
<p>Two thoughts (that I haven't actually tried in godbolt):</p>
<ul>
<li>if it's over a slice specifically, <code>.as_chunks::&lt;2&gt;()</code> on nightly would probably be perfect for this, or just <code>.chunks(2)</code> would be pretty good on stable.</li>
<li>I've seen other <code>step_by</code>s that are much improved by <code>for_each</code> instead of <code>for</code>.</li>
</ul>



<a name="236508185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/step_by%20%3D%3E%20optimization%20fail%20%2384621/near/236508185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/step_by.20.3D.3E.20optimization.20fail.20.2384621.html#236508185">(Apr 28 2021 at 13:40)</a>:</h4>
<p>Oh interesting, thanks <span class="user-mention" data-user-id="125270">@scottmcm</span> !</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>